package com.compass.mobile.ui.viewModel

import androidx.lifecycle.MutableLiveData
import com.compass.mobile.framework.constant.BASE_AI
import com.compass.mobile.framework.constant.BASE_COMMON
import com.compass.mobile.framework.utils.TipsToast
import com.compass.mobile.models.AiData
import com.compass.mobile.models.AiDataWarp
import com.compass.mobile.models.CommonBean
import com.compass.mobile.models.MsgWarp
import com.compass.mobile.network.callback.IApiErrorCallback
import com.compass.mobile.network.manager.ApiManager
import com.compass.mobile.network.viewmodel.BaseViewModel
import com.google.gson.JsonObject
import toJson

/**
 * Description： 智能导诊ViewModel
 * Date:2024/7/1 13:46
 */
class IntelligentGuidanceViewModel : BaseViewModel() {

    val aiDataLiveData = MutableLiveData<MsgWarp?>()
    val commonListLiveData = MutableLiveData<MutableList<CommonBean>?>()


    private fun getRequestBody(event: String?, aiData: AiData?): AiDataWarp {
        return AiDataWarp(
            "1",
            event,
            UserInfoManager.getHospitalIdCode(),
            UserInfoManager.getPatientInfo()?.id,
            aiData
        )
    }


    fun intelligentGuidance(event: String?, aiData: AiData?) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.intelligentGuidance(BASE_AI, getRequestBody(event, aiData))
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            aiDataLiveData.value = it
        })
    }




    fun commonSymptoms(age: String?, sex: String?) {
        launchUIWithResult(responseBlock = {
            ApiManager.api.commonSymptoms(BASE_COMMON, age, sex)
        }, errorCall = object : IApiErrorCallback {
            override fun onError(code: Int?, error: String?) {
                TipsToast.showTips(error)
            }
        }, successBlock = {
            commonListLiveData.value=it
        })
    }
}